package com.bckj.freshnow.user.service;

import com.bckj.freshnow.user.entity.User;
import com.bckj.freshnow.user.mapper.UserMapper;
import com.bckj.freshnow.user.repo.UserRepository;
import com.bckj.freshnow.user.convert.UserConvert;
import com.bckj.freshnow.user.model.UserResponse;
import com.bckj.freshnow.user.model.UserRequest;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户表(User)service
 *
 * @author makejava
 * @since 2025-04-21 09:35:37
 */
@Service
@RequiredArgsConstructor
public class UserService {

    private final UserRepository userRepository;
    private final UserMapper userMapper;
    private final UserConvert userConvert;
	
    /**
     * 列表
     *
     * @param request req
     * @return list
     */
    public List<UserResponse> findAll(UserRequest request){
        return userMapper.findAll(request);
    }
    
    /**
     * 详情
     *
     * @param id id
     * @return vo
     */
    public UserResponse details(Long id) {
        User entity = userRepository.getById(id);
        return userConvert.bean2Response(entity);
    }
    
    /**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
    public boolean saveUser(UserRequest request) {
        User data = userConvert.request2Bean(request);
        return userRepository.save(data);
    }
    
    /**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	public boolean updateUser(UserRequest request) {
        User data = userConvert.request2Bean(request);
        return userRepository.updateById(data);
	}

	/**
	 * 根据Id移除
	 *
	 * @param id id
	 * @return boolean
	 */
	public boolean remove(Long id) {
		return userRepository.removeById(id);
	}
}

